<?php

namespace app\admin\controller\company;

use app\common\controller\Backend;

class Setting extends Backend
{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\company\Setting();
        $this->view->engine->layout('company/layout');
    }

    public function import()
    {
        parent::import();
    }

    public function settingEdit()
    {
        $rows = $this->model->all();
        $settings = [];
        foreach ($rows as $value) {
            $settings[$value->name] = $value->value;
        }

        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");

            foreach ($params as $key => $value) {
                $kk = $this->model->where('name', $key)->find();
                $kk->value = $value;
                $kk->save();
            }

            $this->success("保存成功");
        }

        $this->view->assign('data',  $settings);

        return $this->view->fetch('setting_edit');
    }

}

